<template>
    <div class="MonitoringDynamics">
        <div class="top">
            <div class="left">
                <SubTitle subTitle="监测动态"></SubTitle>
                <div class="scroll">
                    <vue-seamless-scroll ref="scroll3" :data="actives" class="scrollb" :class-option="classOption">
                        <div :class="['scrollb-item', index % 2 == 0 ? 'colorDeep' : '']" v-for="(item, index) in actives"
                            :key="index">
                            <div class="text">监测到{{ item.speciesName }}（{{ item.bodyLength }}cm、{{ item.weight }}g）活动行为。</div>
                            <div class="time">{{ item.createdTime }}</div>
                        </div>
                    </vue-seamless-scroll>
                </div>
                <div class="imgList">
                    <!-- <img src="@assets/bird.png" alt="" v-for="item in [1, 2, 3, 4, 5, 6]" :key="item" /> -->
                     <div v-for="(item , index) in images" :key="index"  @click="showPop(item,true)">
                        <img :src="`${$imageServer}${item.imageUrl}`" alt=""  />
                        <p>{{ item.createdTime }}</p>
                     </div>
                    
                </div>
            </div>
            <div class="right">
                <div class="titleP">
                    <p class="name">{{ deviceInfo.monitorPointName }}</p>
                    <p :class="['type', deviceInfo.status == true ? 'online' : 'outline']">
                        {{ deviceInfo.status == true ? "在线" : "离线" }}
                    </p>
                </div>
                <div class="position">
                    <img src="../../../assets/pos.png" alt="" />
                    <p>{{ deviceInfo.address }}</p>
                </div>
                <p class="setTime">安装时间：{{ deviceInfo.installDate }}</p>
                <div class="banner">
                    <img src="../../../assets/banner.png" alt="" />
                </div>
                <div class="bottomList">
                    <div class="item">
                        <p>
                            <img :src="require(`@assets/monitor/p${1}.png`)">
                            <span>{{ getDirection(deviceInfo.direction) }}</span>
                        </p>
                        <p>鸟巢朝向</p>
                    </div>
                    <div class="item">
                        <p>
                            <img :src="require(`@assets/monitor/p${2}.png`)">
                            <span>{{ deviceInfo.lon }}</span>
                        </p>
                        <p>经度</p>
                    </div>
                    <div class="item">
                        <p>
                            <img :src="require(`@assets/monitor/p${3}.png`)">
                            <span>{{ deviceInfo.lat }}</span>
                        </p>
                        <p>纬度</p>
                    </div>
                    <div class="item">
                        <p>
                            <img :src="require(`@assets/monitor/p${4}.png`)">
                            <span>{{ deviceInfo.alt }}</span>
                        </p>
                        <p>海拔</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="third">
          <SubTitle subTitle="鸟类活动频次">
            <div style="width: 2rem; margin-left: auto;">
                <el-select v-model="birdSelectTime"  @change="selectChange" placeholder="请选择">
                <el-option value="Month" label="月份"></el-option>
                <el-option value="Day" label="小时"></el-option>
                </el-select>
            </div>
          </SubTitle>
          <div class="chart-box" style="width: 100%; height: 150px;">
            <Charts  :option="nlhdjlOption" />

            <!-- <div v-for="(item , index) in chartLabel" :key="index" style="width: 100%; height: 80%;" class="chart-item">
                <p  style="text-align: center; margin-top: 20px;">{{ item.name }}</p>
              
            </div> -->
          </div>
        </div>

        <div class="third">
            <SubTitle subTitle="监测目标体长"></SubTitle>
          <div class="chart-box" style="width: 100%; height: 150px;">
            <Charts  :option="jcmbtcOption" />
          </div>
        </div>
        <div class="third">
            <SubTitle subTitle="监测目标体重"></SubTitle>
          <div class="chart-box" style="width: 100%; height: 150px;">
            <Charts  :option="jcmbtzOption" />
          </div>
        </div>
        <div class="third">
            <SubTitle subTitle="环境温度"></SubTitle>
          <div class="chart-box" style="width: 100%; height: 150px;">
            <Charts  :option="hjwdOption" />
          </div>
        </div>
        <div class="third">
            <SubTitle subTitle="环境湿度"></SubTitle>
          <div class="chart-box" style="width: 100%; height: 150px;">
                <Charts  :option="hjsdOption" />
          </div>
        </div>

        <!-- <div class="bottom">
            <SubTitle subTitle="鸟类活动节律">
                <p class="slotLabel"><span>24小时</span> <span>年度</span></p>
            </SubTitle>
            <div class="chart-box">
                <charts :option="option" />
            </div>
        </div> -->
    </div>
</template>

<script>
import SubTitle from "@/components/commons/SubTitle.vue";
import Charts from "@/components/commons/Charts.vue";

import { getSnapshot,getStatistics } from '../../../api/index';

export default {
    name: "MonitoringDynamics",
    props:['basePosition',"deviceInfo"],
    // props: {
    //     basePosition: {
    //         type: Number,
    //         default: 1,
    //     },
    // },
    components: {
        SubTitle,
        Charts,
    },
    data() {
        return {
            actives:[],
            images:[],
            nlhdjlOption:{},
            jcmbtcOption:{},
            jcmbtzOption:{},
            hjwdOption:{},
            hjsdOption:{},
            birdSelectTime : 'Month'
        };
    },
    methods: {
        setChartData() {
         
            let that= this ;
            // this.birdSelectTime 将要请求的参数
            this.nlhdjlOption={};
            this.jcmbtcOption={};
            this.jcmbtzOption={};
            this.hjwdOption={};
            this.hjsdOption={};
      },
      selectChange(value) {
            console.log(value)
          this.birdSelectTime = value ;
        //   this.setChartData()
          this.InitEchart(value);
      },
      getDirection(direction){
        switch(direction){
            case 0:
                return '未知'
            case 1:
                return '东'
            case 2:
                return '南';
            case 3:
                return '西';
            case 4:
                return '北';
            case 5:
                return '东北';
            case 6:
                return '东南';
            case 7:
                return '西北';
            case 8:
                return '西南';
        }
        return '未知' 
      },
      getMonitor(){
     
        getSnapshot({id:this.deviceInfo.umID}).then(res=>{
            console.log(res)
            if(res.status != 200){
                this.$message.error(res.data.data);
            }else{
                if(res.data.data&&res.data.data.monitoringActives){
                    this.actives = res.data.data.monitoringActives;
                    this.images = res.data.data.monitoringActives ;
                }
            }
        }).catch(ex=>{
            this.$message.error(ex)
        });
      },
      InitEchart(key){
        var self = this;
        getStatistics({id:this.deviceInfo.umID,key:key}).then(res=>{
            console.log(res)
            
            if(res.status != 200){
                this.$message.error(res.data.data);
            }else{
                if(res.data.data&&res.data.data.length>0){
                    var axis = res.data.data.map(o=>o.key);
                    self.nlhdjlOption = self.createOption(axis,res.data.data.map(o=>o.num));
                    self.jcmbtcOption = self.createOption(axis,res.data.data.map(o=>o.tc));
                    self.jcmbtzOption = self.createOption(axis,res.data.data.map(o=>o.tz));
                    self.hjwdOption = self.createOption(axis,res.data.data.map(o=>o.wd));
                    self.hjsdOption = self.createOption(axis,res.data.data.map(o=>o.sd));
                }
            }
        }).catch(ex => {
            this.$message.error(ex)
        })
      },
      createOption(axis,data){
        return {
                grid: {
                    top:"8%",
                    left: "3%",
                    right: "4%",
                    bottom: "3%",
                    containLabel: true,
                },
                xAxis: [
                    {
                        type: "category",
                        boundaryGap: false,
                        axisLine: {
                            show:false,
                            lineStyle: {
                                color: "#ccc",
                            },
                        },
                        axisLabel: {
                            margin: 10,
                            textStyle: {
                                fontSize: 12,
                                color: "#fff",
                            },
                        },
                        data: axis,
                    },
                ],
                yAxis: [
                    {
                        type: "value",
                        name: "",
                        axisTick: {
                            show: false,
                        },
                        axisLine: {
                            lineStyle: {
                                color: "#fff",
                            },
                            show:false
                        },
                        axisLabel: {
                            margin: 10,
                            textStyle: {
                                fontSize: 12,
                                color: "#fff",
                            },
                        },
                        splitLine: {
                            lineStyle: {
                                type: "dash",
                                color: "rgba(255, 255, 255, 0.2)",
                            },
                        },
                    },
                ],
                series: [
                    {
                        name: "",
                        type: "line",
                        smooth: false,
                        symbol: "circle",
                        symbolSize: 5,
                        showSymbol: false,
                        lineStyle: {
                            normal: {
                                width: 1,
                            },
                        },

                        itemStyle: {
                            normal: {
                                color: "#71F754",
                                borderColor: "rgba(0,136,212,0.2)",
                                borderWidth: 12,
                            },
                        },
                        data: data,
                    },
                ],
            }
      },
      showPop(item,isImg){
        console.log(isImg)
        window.MonitoringDynamics && window.MonitoringDynamics.setPopData(item,isImg)
      }
    },
    computed: {
        classOption() {
            return {
                step: 0.2, // 数值越大速度滚动越快
                limitMoveNum: 2, // 开始无缝滚动的数据量 this.dataList.length
                hoverStop: true, // 是否开启鼠标悬停stop
                direction: 1, // 0向下 1向上 2向左 3向右
                openWatch: true, // 开启数据实时监控刷新dom
                singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
                singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
                waitTime: 1000, // 单步运动停止的时间(默认值1000ms)
            };
        },
    },
    mounted() {
    
        this.InitEchart(this.birdSelectTime);
        this.getMonitor();
    }
};
</script>

<style lang="scss" scoped>
.MonitoringDynamics {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .top {
        display: flex;

        justify-content: space-between;
        width: calc(100% - 44px);

        .left {
            padding: 12px 20px;
            background: linear-gradient(90deg,
                    rgba(25, 99, 135, 0.05) 0%,
                    rgba(25, 99, 135, 0.25) 100%);
            width: 1056px;
            height: 680px;

            .scroll {
                margin-top: 20px;
                width: 1007px;
                height: 306px;
                overflow: hidden;
                background: linear-gradient(90deg,
                        rgba(25, 99, 135, 0.05) 0%,
                        rgba(25, 99, 135, 0.25) 100%);

                .scrollb-item {
                    display: flex;
                    justify-content: space-between;
                    padding: 14px 36px;
                    height: 50px;
                }

                .colorDeep {
                    background: linear-gradient(90deg,
                            rgba(115, 255, 247, 0.18) 0%,
                            rgba(115, 255, 247, 0.3) 100%);
                }
            }

            .imgList {
                margin-top: 10px;
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                max-height: 270px;
                overflow-y:auto ;
                >div {
                    width: 324px;
                    height: 128px;
                    position: relative; 
                    margin-bottom: 10px;
                    >p {
                         position: absolute;
                        bottom: 0;
                        left: 0;
                        width: 100%;
                        height: 20px;
                        line-height: 20px;
                        background: rgba(0, 0, 0, 0.5);
                    }
                    img {
                 
                        width: 324px;
                        height: 128px;
                    }
                }

                
            }
        }

        .right {
            height: 680px;
            width: 534px;
            background: linear-gradient(90deg,
                    rgba(25, 99, 135, 0.05) 0%,
                    rgba(25, 99, 135, 0.25) 100%);
            padding: 0 20px;

            .titleP {
                margin-top: 50px;
                margin-left: 20px;
                display: flex;
                align-items: center;
                height: 36px;

                .name {
                    font-family: PangMenZhengDao;
                    font-size: 36px;
                    letter-spacing: 0.2em;
                }

                .type {
                    margin-left: 20px;
                    width: 60px;
                    height: 25px;
                    border-radius: 20px;
                    border: 1px solid #ffffff52;
                    text-align: center;
                    padding-left: 10px;
                    position: relative;
                }

                .online {
                    background: linear-gradient(90deg,
                            rgba(178, 255, 181, 0.49) 0%,
                            rgba(178, 255, 181, 0.1) 100%);

                    &::before {
                        content: "";
                        border-radius: 50%;
                        position: absolute;
                        left: 4px;
                        top: 6px;
                        width: 10px;
                        height: 10px;
                        background: #71f754;
                        box-shadow: 0px 0px 4px 0px #71f754;
                    }
                }

                .outline {
                    background: linear-gradient(90deg,
                            rgba(255, 178, 178, 0.49) 0%,
                            rgba(255, 178, 178, 0.1) 100%);

                    &::before {
                        content: "";
                        border-radius: 50%;
                        position: absolute;
                        left: 4px;
                        top: 6px;
                        width: 10px;
                        height: 10px;
                        background: #f75454;
                        box-shadow: 0px 0px 4px 0px #f75454;
                    }
                }
            }

            .position {
                margin-top: 28px;
                margin-left: 20px;
                display: flex;
                align-items: center;
                font-family: PangMenZhengDao;
                font-size: 20px;

                img {
                    width: 26px;
                    height: 26px;
                    margin-right: 10px;
                }
            }

            .setTime {
                margin-left: 20px;
                margin-top: 10px;
                font-family: Source Han Sans;
            }

            .banner {
            background: url('../../../assets/banner-bg.png') no-repeat;
            background-size: 100% 100%;
                img {
                    width: 100%;
                }
            }

            .bottomList {
                display: flex;
                justify-content: space-between;

                >div {
                    width: 113px;
                    height: 60px;
                    padding: 10px;
                    border-radius: 6px;
                    background: rgba(25, 99, 135, 0.3);
                    backdrop-filter: blur(10px);

                    p:nth-of-type(1) {
                        img {
                            width: 20px;
                            margin-right: 10px;
                        }

                        display: flex;
                        font-weight: bold;
                    }

                    p:nth-of-type(2) {
                        margin-top: 8px;
                        font-family: Source Han Sans;
                        font-size: 10px;
                        color: rgba(255, 255, 255, 0.5);
                    }
                }
            }
        }
    }

    .bottom {
        padding: 26px 24px;
        width: calc(100% - 44px);
        height: 263px;
        background: linear-gradient(90deg,
                rgba(25, 99, 135, 0.15) 0%,
                rgba(25, 99, 135, 0.35) 100%);

        .slotLabel {
            position: absolute;
            right: 0;
            width: 100px;
            display: flex;
            justify-content: space-between;
            font-family: Source Han Sans;
            font-size: 12px;
        }

        .chart-box {
            width: 100%;
            height: 180px;
        }
    }
}
.third {
      margin-top: 20px;
      padding: 20px;
      background: linear-gradient(90deg, rgba(25, 99, 135, 0.25) 0%, rgba(25, 99, 135, 0.35) 100%);
      height: 280px;
      .chart-box {
          width: 100%;
          height: 100%;
          display: flex;
          justify-content: space-between;
      }
      ::v-deep{
        
        .el-input__inner {
         
            height: 32px;
      
            background: rgba(18, 28, 38, 0.1);
            color: #fff;
            border: none;
            }
      }
    }

</style>